package com.gsit.expenditure.domain;


import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotEmpty;

@Entity
@Table(name = "vehicle")
@NamedQueries({@NamedQuery (name= "Vehicle.findAll",query= "select vehicle from Vehicle vehicle")})
public class Vehicle extends BaseEntity {

	@NotNull(message="Vehicle Number is required")
	@NotEmpty(message="Vehicl Number is required")
	@Column(name = "vehicleNumber")
	private String vehicleNumber;


	@NotNull(message="Vehicle Name is required")
	@NotEmpty(message="Vehicle Name is required")
	@Column(name = "vehicleName")
	private String vehicleName;

	@NotNull(message="Vehicle Type is required")
	@NotEmpty(message="Vehicle Type is required")
	@Column(name = "vehicleType")
	private String vehicleType;

	@NotNull(message="Model Name is required")
	@NotEmpty(message="Model Name is required")
	@Column(name = "modelName")
	private String modelName;

	@Column(name = "engineNumber")
	private String engineNumber;
	
	@Column(name = "manufacturedYear", nullable = true)
	private String manufacturedYear;
	
	
	//@NumberFormat(style=Style.NUMBER)
	/*@Pattern(regexp ="(^$|[0-9]{10})")
	@Size(min=0,max=10)
	@NotEmpty(message="Rate is required")
	*/
	
	//@Pattern(regexp ="(^$|[0-9]{10})")
	//@Enumerated(EnumType.STRING)
	
	@Min(value=1,message="Should be greater than or equal to 1")
	@NotNull(message="Rate is required")
	@Column(name = "rate")
	private Double rate;
	
	
	@ManyToOne(cascade=CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "vendor_id")
	private Vendor vendor;
		
	@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
	private Set<Bill> bills;
	
	
	@Transient
    private Boolean select = Boolean.FALSE;
	
	public Boolean getSelect() {
		return select;
	}
	
	public String getVehicleNumber() {
		return vehicleNumber;
	}

	public void setVehicleNumber(String vehicleNumber) {
		this.vehicleNumber = vehicleNumber;
	}

	public String getVehicleName() {
		return vehicleName;
	}

	public void setVehicleName(String vehicleName) {
		this.vehicleName = vehicleName;
	}

	public String getVehicleType() {
		return vehicleType;
	}

	public void setVehicleType(String vehicleType) {
		this.vehicleType = vehicleType;
	}

	public String getModelName() {
		return modelName;
	}

	public void setModelName(String modelName) {
		this.modelName = modelName;
	}

	public String getEngineNumber() {
		return engineNumber;
	}

	public void setEngineNumber(String engineNumber) {
		this.engineNumber = engineNumber;
	}

	public String getManufacturedYear() {
		return manufacturedYear;
	}

	public void setManufacturedYear(String manufacturedYear) {
		this.manufacturedYear = manufacturedYear;
	}

	
	public Vendor getVendor() {
		return vendor;
	}

	public void setVendor(Vendor vendor) {
		this.vendor = vendor;
	}


	public Set<Bill> getBills() {
		return bills;
	}


	public void setBills(Set<Bill> bills) {
		this.bills = bills;
	}


	public void setSelect(Boolean select) {
		this.select = select;
	}

	public Double getRate() {
		return rate;
	}

	public void setRate(Double rate) {
		this.rate = rate;
	}




	@Override
	public String toString() {
		return "Vehicle [vehicleNumber=" + vehicleNumber + ", vehicleName="
				+ vehicleName + ", vehicleType=" + vehicleType + ", modelName="
				+ modelName + ", engineNumber=" + engineNumber
				+ ", manufacturedYear=" + manufacturedYear + ", rate=" + rate
				+ ", vendor=" + vendor + ", billSet=" + bills + ", select="
				+ select + ", getId()=" + getId() + ", getCreatedDate()="
				+ getCreatedDate() + ", getModifiedDate()=" + getModifiedDate()
				+ ", getVersion()=" + getVersion() + ", getClass()="
				+ getClass() + ", hashCode()=" + hashCode() + ", toString()="
				+ super.toString() + "]";
	}

	
}
